//
// Created by zhou on 2019/9/14.
//汉诺塔（Tower of Hanoi）
//

#ifndef _RECURSIVE_ALGORITHM_HANNOTA_H
#define _RECURSIVE_ALGORITHM_HANNOTA_H

#endif //_RECURSIVE_ALGORITHM_HANNOTA_H

int i = 1;//定义全局变量，每次调用后加1
void Hanoi(int n, char A, char B, char C)
{

    if (n == 1)//如果只有一个直接从A移到B   "%2d-(%2d):%c==>%c\n"
    {
        printf("%2d-(%2d):%c==>%c\n",i++,n,A,B);
    }else
    {
        Hanoi(n - 1, A, C, B);//把n - 1个从A移到C借助B
        printf("%2d-(%2d):%c==>%c\n", i++, n, A, B);
        Hanoi(n - 1, C, B, A);//把n - 1个从C移到B借助B
    }
}

void hannota()
{
    int n;
    char A = 'A'; //定义ABC表示三个柱子
    char B = 'B';
    char C = 'C';
    printf("Please enter the number of discs: ");
    scanf("%d", &n);
    Hanoi(n, A, B, C);
    printf("\tTotal:%d\n",--i);
}